<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label-width="100px" label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="联系方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系方式"
          clearable
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="驾驶证状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择驾驶证状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.driver_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="handleAdd"
          >添加</el-button
        >
        <el-button type="primary" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="data"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="姓名" prop="name" width="120" />
      <el-table-column
        label="性别"
        prop="roleName"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column
        label="年龄"
        prop="age"
        :show-overflow-tooltip="true"
        width="150"
      />
      <el-table-column label="证件号码" prop="idCard" width="100" />
      <el-table-column label="联系电话" align="phone" width="100" />
      <el-table-column
        label="准驾车型"
        align="center"
        prop="allowType"
        width="180"
      />
      <el-table-column
        label="驾驶证状态"
        align="center"
        prop="status"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.status) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"
            >查看详情</el-button
          >
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <AddAndEdit @success="getList" ref="AddAndEditRef" />
  </div>
</template>

<script>
import { getDriverList } from "@/api/files/driver.js";
import AddAndEdit from "./addAndEdit.vue";

export default {
  name: "driver",
  dicts: ["driver_status"],
  components: { AddAndEdit },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 列表数据
      data: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        idCard: undefined,
        name: undefined,
        phone: undefined,
        status: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      getDriverList(this.queryParams).then(
        (response) => {
          this.total = response.total;
          this.data = response.rows;
        },
        (error) => {
          console.log("error: ", error);
        }
      );
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleAdd() {
      this.$refs.AddAndEditRef.open();
    },
    handleDetail() {
      this.$router.push({
        name: "driverDetail",
        // path:"/details/driverDetail"
      });
    },
    handleUpdate(row) {
      this.$refs.AddAndEditRef.open(row.id);
    },
  },
};
</script>
